//
//  GRJMasonryViewController.m
//  GRJTolCayFrwk
//
//  Created by 易上云 on 2017/3/10.
//  Copyright © 2017年 Global Barter. All rights reserved.
//

#import "GRJMasonryViewController.h"
#import "Masonry.h"
#import "UIView+GRJFrame.h"

@interface GRJMasonryViewController ()

@end

@implementation GRJMasonryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"Masonry";
    
    
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    

    // 1.创建蓝色的view
    UIView *blueView = [[UIView alloc]init];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    
    // 2.创建红色的view
    UIView *redView = [[UIView alloc ] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    
    // 3.添加蓝色View约束
    //此处不能使用UIView+GRJFrame,blueView/redView相互拿不到彼此的尺寸
    
    
    // 添加新的约束
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(self.view.grj_left)).offset(30);
        make.bottom.equalTo(@(self.view.grj_bottom)).offset(-30);
        make.right.equalTo(redView.mas_left).offset(-30);
        //make.right.equalTo(@(redView.grj_left)).offset(-30);
        make.width.equalTo(redView.mas_width);
        //make.width.equalTo(@(redView.grj_width));
        make.height.equalTo(@(50));
    }];
    
    // 4.添加红色View约束
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.right.equalTo(self.view.mas_right).offset(-30);
        make.right.equalTo(@(self.view.grj_right)).offset(-30);
        make.top.equalTo(blueView.mas_top);
        //make.top.equalTo(@(blueView.grj_top));
        make.bottom.equalTo(blueView.mas_bottom);
        //make.bottom.equalTo(@(blueView.grj_bottom));
    }];
    
    /*
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(30);
        make.bottom.equalTo(self.view.mas_bottom).offset(-30);
        make.right.equalTo(redView.mas_left).offset(-30);
        make.width.equalTo(redView.mas_width);
        make.height.equalTo(@(50));
    }];
    
    // 4.添加红色View约束
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-30);
        make.top.equalTo(blueView.mas_top);
        make.bottom.equalTo(blueView.mas_bottom);
    }];
     */
    // 4.更新约束
    //    [blueView updateConstraints:^(MASConstraintMaker *make) {
    //        make.height.equalTo(80);
    //    }];
    
    // 5.删除之前所有约束,重新添加新的约束
    //    [blueView remakeConstraints:^(MASConstraintMaker *make) {
    //
    //    }];
}



-(void)manyType{
    // 1.创建红色的view
    UIView *redView = [[UIView alloc ] init];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    
    // 2.添加约束
    //    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.width.equalTo(@100);
    //        make.height.equalTo(@100);
    //        make.centerX.equalTo(self.view.mas_centerX);
    //        make.centerY.equalTo(self.view.mas_centerY);
    //    }];
    //    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.width.mas_equalTo(100);
    //        make.height.mas_equalTo(100);
    //        make.centerX.mas_equalTo(self.view.mas_centerX);
    //        make.centerY.mas_equalTo(self.view.mas_centerY);
    //    }];
    
    //    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.width.mas_equalTo(100);
    //        make.height.mas_equalTo(100);
    //        make.centerX.mas_equalTo(self.view);
    //        make.centerY.mas_equalTo(self.view);
    //    }];
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 100));
        make.center.mas_equalTo(self.view);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
